package com.ruoyi.fantasy.service.impl;

import java.util.List;
import java.util.Map;

import com.huanzhidadi.fantasy.bean.domain.FantasyTitleType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.fantasy.common.WorldInit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.fantasy.mapper.FantasyTitleMapper;
import com.huanzhidadi.fantasy.bean.domain.FantasyTitle;
import com.ruoyi.fantasy.service.IFantasyTitleService;
import com.ruoyi.common.core.text.Convert;

/**
 * 称号Service业务层处理
 * 
 * @author wanghui
 * @date 2020-04-11
 */
@Service
public class FantasyTitleServiceImpl implements IFantasyTitleService 
{
    @Autowired
    private FantasyTitleMapper fantasyTitleMapper;

    /**
     * 查询称号
     * 
     * @param id 称号ID
     * @return 称号
     */
    @Override
    public FantasyTitle selectFantasyTitleById(String id)
    {
        return fantasyTitleMapper.selectFantasyTitleById(id);
    }

    /**
     * 查询称号列表
     * 
     * @param fantasyTitle 称号
     * @return 称号
     */
    @Override
    public List<FantasyTitle> selectFantasyTitleList(FantasyTitle fantasyTitle)
    {
        return fantasyTitleMapper.selectFantasyTitleList(fantasyTitle);
    }

    /**
     * 新增称号
     * 
     * @param fantasyTitle 称号
     * @return 结果
     */
    @Override
    public int insertFantasyTitle(FantasyTitle fantasyTitle)
    {
        fantasyTitle.setCreateTime(DateUtils.getNowDate());
        return fantasyTitleMapper.insertFantasyTitle(fantasyTitle);
    }

    /**
     * 修改称号
     * 
     * @param fantasyTitle 称号
     * @return 结果
     */
    @Override
    public int updateFantasyTitle(FantasyTitle fantasyTitle)
    {
        fantasyTitle.setUpdateTime(DateUtils.getNowDate());
        return fantasyTitleMapper.updateFantasyTitle(fantasyTitle);
    }

    /**
     * 删除称号对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteFantasyTitleByIds(String ids)
    {
        return fantasyTitleMapper.deleteFantasyTitleByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除称号信息
     * 
     * @param id 称号ID
     * @return 结果
     */
    @Override
    public int deleteFantasyTitleById(String id)
    {
        return fantasyTitleMapper.deleteFantasyTitleById(id);
    }

    @Override
    public void transforData(List<FantasyTitle> list) {
        Map<String, FantasyTitleType> titleTypeMap = WorldInit.titleTypeMap;
        for (FantasyTitle fantasyTitle : list) {
            if (fantasyTitle.getTypeId() != null) {
                if (titleTypeMap.get(fantasyTitle.getTypeId()) != null) {
                    fantasyTitle.setTypeId(titleTypeMap.get(fantasyTitle.getTypeId()).getTypeName());
                }
            }
        }
    }
}
